DIR_INC := ./inc
DIR_SRC := ./src
DIR_OBJ := ./obj
DIR_BIN := ./bin


vpath %.h $(DIR_INC)
vpath %.c $(DIR_SRC)
vpath %.o $(DIR_OBJ)

SRC := $(wildcard ${DIR_SRC}/*.c)  
OBJ := $(patsubst %.c, ${DIR_OBJ}/%.o, $(notdir ${SRC}))

TARGET := lst_demo

INC := -I${DIR_INC} 
CFLAGS := -Wall $(INC) -g
LDFLAGS := -lpthread #-lprotobuf-c -lpaho-mqtt3a

all:build_target $(DIR_BIN)/$(TARGET) 

build_target:mkoutdir $(OBJ)
	$(CC) $(LDFLAGS) -o $(DIR_BIN)/$(TARGET) $(OBJ)

${DIR_OBJ}/%.o:${DIR_SRC}/%.c
	$(CC) $(CFLAGS) -o $@ -c $<


mkoutdir:
	rm -rf $(DIR_OBJ)
	mkdir $(DIR_OBJ)
	rm -rf $(DIR_BIN)
	mkdir $(DIR_BIN)

.PHONY:clean
clean:
	rm -rf $(DIR_OBJ)/ $(DIR_BIN)/
